package com.yeming.flink.practice

import org.apache.flink.streaming.api.scala._

object FlinkStreamWordCount {

  def main(args: Array[String]): Unit = {

    //initialize environment variable
    val streamEnv = StreamExecutionEnvironment.getExecutionEnvironment
    //set parallize
    streamEnv.setParallelism(1)
    //read data
    val stream = streamEnv.socketTextStream("f1", 9999)
    //transfer compute
    val result = stream.flatMap(_.split(","))
      .map((_, 1)).setParallelism(2)
      .keyBy(0)
      .sum(1).setParallelism(2)

    result.print()

    streamEnv.execute("WordCount")

  }
}
